use napi_derive_ohos::napi;

/// 处理传感器数据，参数改为 f64 接收，再转 f32 处理
#[napi]
pub fn process_sensor_data(
    acceleration_x: f64,
    acceleration_y: f64,
    acceleration_z: f64,
    gyroscope_x: f64,
    gyroscope_y: f64,
    gyroscope_z: f64,
) -> (f32, f32) {
    // 转为 f32 方便后续计算
    let ax = acceleration_x as f32;
    let ay = acceleration_y as f32;
    let az = acceleration_z as f32;

    let gx = gyroscope_x as f32;
    let gy = gyroscope_y as f32;
    let gz = gyroscope_z as f32;

    // 计算加速度向量大小
    let acceleration_magnitude = (ax.powi(2) + ay.powi(2) + az.powi(2)).sqrt();
    // 计算陀螺仪平均值
    let gyroscope_average = (gx + gy + gz) / 3.0;

    (acceleration_magnitude, gyroscope_average)
}

